<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-panel" [class.stroked]="stroked" [formGroup]="barWidthSettingsFormGroup">
  <div fxLayout="row" fxLayoutAlign="space-between center">
    <div fxFlex translate>widgets.time-series-chart.no-aggregation-bar-width-strategy</div>
    <tb-toggle-select formControlName="strategy" selectMediaBreakpoint="xs">
      <tb-toggle-option *ngFor="let strategy of timeSeriesChartNoAggregationBarWidthStrategies" [value]="strategy">
        {{ timeSeriesChartNoAggregationBarWidthStrategyTranslations.get(strategy) | translate }}
      </tb-toggle-option>
    </tb-toggle-select>
  </div>
  <ng-container *ngIf="barWidthSettingsFormGroup.get('strategy').value === TimeSeriesChartNoAggregationBarWidthStrategy.group">
    <ng-container
      *ngTemplateOutlet="barWidth;
      context: {
        formGroup: barWidthSettingsFormGroup.get('groupWidth'),
        label: 'widgets.time-series-chart.bar-group-width'
      }">
    </ng-container>
  </ng-container>
  <ng-container *ngIf="barWidthSettingsFormGroup.get('strategy').value === TimeSeriesChartNoAggregationBarWidthStrategy.separate">
    <ng-container
      *ngTemplateOutlet="barWidth;
      context: {
        formGroup: barWidthSettingsFormGroup.get('barWidth'),
        label: 'widgets.time-series-chart.bar-width'
      }">
    </ng-container>
  </ng-container>
</div>
<ng-template #barWidth let-label="label" let-formGroup="formGroup">
  <div class="tb-form-row space-between column-lt-md" [formGroup]="formGroup">
    <div translate>{{ label }}</div>
    <div fxLayout="row" fxFlex.lt-md fxLayoutAlign="start center" fxLayoutGap="8px">
      <mat-form-field class="medium-width" fxFlex.lt-md appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="relative">
          <mat-select-trigger>
            {{ (formGroup.get('relative').value ?
               'widgets.time-series-chart.bar-width-relative' :
               'widgets.time-series-chart.bar-width-absolute') | translate }}
          </mat-select-trigger>
          <mat-option [value]="true">
            {{ 'widgets.time-series-chart.bar-width-relative' | translate }}
          </mat-option>
          <mat-option [value]="false">
            {{ 'widgets.time-series-chart.bar-width-absolute' | translate }}
          </mat-option>
        </mat-select>
      </mat-form-field>
      <mat-form-field *ngIf="formGroup.get('relative').value" class="number fixed-width" appearance="outline" subscriptSizing="dynamic">
        <input required matInput type="number" formControlName="relativeWidth" min="0.1" max="100" placeholder="{{ 'widget-config.set' | translate }}"/>
        <span matSuffix>%</span>
      </mat-form-field>
      <mat-form-field *ngIf="!formGroup.get('relative').value" class="number fixed-width" appearance="outline" subscriptSizing="dynamic">
        <input required matInput type="number" formControlName="absoluteWidth" min="100" step="1" placeholder="{{ 'widget-config.set' | translate }}"/>
        <span matSuffix>ms</span>
      </mat-form-field>
    </div>
  </div>
</ng-template>
